home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / POOL.C < prev    next >
C/C++ Source or Header  |  1996-08-29  |  1KB  |  41 lines

  1. #include "global.h"
  2. #ifdef POOLED
  3. #include "pool.h"
  4.  
  5. #if !defined(_lint)
  6. static char rcsid[] OPTIONAL = "$Id: pool.c,v 1.6 1996/08/29 12:11:16 root Exp root $";
  7. #endif
  8.  
  9. void *pool_alloc (struct mempool *pool)
  10. {
  11. struct mempoolblock *tmp = NULLPOOLBLK;
  12.  
  13.     if (!pool->top || (pool->index == pool->bottom->entries))    {
  14.         tmp = (struct mempoolblock *) callocw (1, ((pool->numentries * pool->size) + sizeof(struct mempoolblock)));    /*lint !e737 */
  15.         if (pool->top)    {
  16.             pool->bottom->next = tmp;
  17.             pool->bottom = tmp;
  18.         } else
  19.             pool->top = pool->bottom = tmp;
  20.         pool->index = 0;
  21.         pool->bottom->entries = pool->numentries;
  22.         pool->bottom->base = (char *)(((long)pool->bottom) + sizeof(struct mempoolblock));    /*lint !e737 */
  23.     }
  24.     return ((void *)&pool->bottom->base[pool->index++ * pool->size]);
  25. }
  26.  
  27.  
  28. void pool_free (struct mempool *pool)
  29. {
  30. struct mempoolblock *temp, *blk;
  31.  
  32.     for (blk = pool->top; blk; blk = temp)    {
  33.         temp = blk->next;
  34.         free(blk);
  35.     }
  36.     pool->top = pool->bottom = NULLPOOLBLK;
  37.     pool->index = 0;
  38. }
  39.             
  40. #endif /* POOLED */
  41.